home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Snippets / TStr255 class / •AZN_TSTR255 / AZN_TStr255.h < prev   
Encoding:
C/C++ Source or Header  |  1995-10-23  |  2.6 KB  |  141 lines  |  [TEXT/CWIE]

  1. #pragma once
  2. /*        
  3. *    AZN_TStr255.h
  4. *
  5. *    Class declaration for 'TStr55' class, a utility
  6. *    class to replace Str255 and allow for easier
  7. *    string manipulation
  8. *    Inheritance:    BASE CLASS
  9. *    
  10. *    © Andrew Nemeth  Warrimoo Australia  1995
  11. *    aznemeng@zeta.org.au
  12. *
  13. *    File created:    5 Jun 95
  14. *    Modified:        5, 28 Jun;
  15. *                2, 23 Oct 95.
  16. */
  17.  
  18.  
  19. #include    <stddef.h>                                    //    defn of 'size_t'
  20.  
  21.  
  22. //    CLASS dec
  23. //
  24. class    TStr255
  25. {
  26.     public:
  27.         TStr255();
  28.         ~TStr255(){};
  29. //                                                        typecast to 'StringPtr'
  30.         operator StringPtr ();
  31. //                                                        construct with Str255
  32.         TStr255( ConstStr255Param );
  33. //                                                        assign/concat Str255
  34.         TStr255 &      operator =    ( ConstStr255Param );
  35.         TStr255 &        operator +=    ( ConstStr255Param );
  36. //                                                        assign/concat C strings
  37.         TStr255 &        operator =     ( const char * );
  38.         TStr255 &        operator +=    ( const char * );
  39. //                                                        assign/concat ONTO C strs
  40.         void            copy2C        ( char * );
  41.         void            cat2C        ( char * );        
  42. //                                                        compare with Str255
  43.         Boolean        operator ==    ( ConstStr255Param );
  44. //                                                        array indexing
  45.         unsigned char    operator []    ( const short );
  46. //                                                        grab class Str255 size byte
  47.         unsigned char    operator *     ();
  48. //                                                        set max length of Str255
  49.         void            setMaxLength    ( const short );
  50.  
  51.     private:
  52.         Str255        f_str255Item;        
  53. //                                                        never create heap-based objects!
  54.         void *        operator new    ( size_t );
  55.  
  56.         short        minNum( short, short );
  57.         long            myStrlen( register char * );
  58. };
  59.  
  60.  
  61.  
  62. //    INLINES
  63. //
  64. inline    TStr255::TStr255()
  65. //
  66. //    Inline constructor
  67. //
  68. {
  69.     f_str255Item[0] = 0;
  70. }
  71.  
  72.  
  73.  
  74. inline TStr255::operator StringPtr ()
  75. //
  76. //    Overloaded typecast operator to 'StringPtr'.
  77. //    This allows object to be used as a replacement
  78. //    Str255 in functions which require this parameter!
  79. //
  80. {
  81.     return( (StringPtr)&f_str255Item[0] );
  82. }
  83.  
  84.  
  85.  
  86. inline TStr255::TStr255( ConstStr255Param str255S )
  87. //
  88. //    Copy Construct with Str255
  89. //
  90. {
  91.     ::BlockMoveData( StringPtr(str255S), f_str255Item, str255S[0] + 1 );
  92. }
  93.  
  94.  
  95.  
  96. inline short        TStr255::minNum( short x, short y )
  97. //
  98. //    Return smallest number
  99. //
  100. {
  101.     return( ( x < y ) ? x : y );
  102. }
  103.  
  104.  
  105.  
  106. inline Boolean        TStr255::operator==( ConstStr255Param str255S )
  107. //
  108. //    Compare object with string
  109. //
  110. {
  111.     return( ::EqualString( str255S, f_str255Item, TRUE, TRUE ) );
  112. }
  113.  
  114.  
  115. inline unsigned char    TStr255::operator[]( const short shNdx )
  116. //
  117. //    Array indexing
  118. //
  119. {
  120.     return( f_str255Item[shNdx] );
  121. }
  122.  
  123.  
  124. inline unsigned char    TStr255::operator * ()
  125. //
  126. //    Grab size byte of Str255
  127. //
  128. {
  129.     return( f_str255Item[0] );
  130. }
  131.  
  132.  
  133. inline void            TStr255::setMaxLength( const short shNdx )
  134. //
  135. //    Set max length of string
  136. //
  137. {
  138.     if ( shNdx >= 0 && shNdx <= 255 )
  139.         f_str255Item[0] = shNdx;
  140. }
  141.